<html>
<head><meta charset="utf-8"><title>folding of `match` and `if` · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html">folding of `match` and `if`</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="176108909"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176108909" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176108909">(Sep 19 2019 at 15:09)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> one thing that I felt regressed when I switched to RA was the folding of <code>match</code> and <code>if</code>... specifically:</p>
<ul>
<li>I cannot fold a <code>match</code> expression at all, only the arms; this becomes a problem for enums with lotsa variants.</li>
<li>When I fold an <code>if</code> expression that also has an <code>else</code> I see the block of the <code>else</code>as-if it was the body of the <code>if</code>:</li>
</ul>
<div class="codehilite"><pre><span></span><span class="k">if</span><span class="w"> </span><span class="n">cond</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">block_if</span><span class="w"></span>
<span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">block_else</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<p>is displayed after folding as:</p>
<div class="codehilite"><pre><span></span><span class="k">if</span><span class="w"> </span><span class="n">cond</span><span class="w"> </span><span class="p">{...</span><span class="w"></span>
<span class="w">    </span><span class="n">block_else</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>



<a name="176109018"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176109018" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176109018">(Sep 19 2019 at 15:10)</a>:</h4>
<p>should be easy to tweak here: <a href="https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide_api/src/folding_ranges.rs" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide_api/src/folding_ranges.rs">https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide_api/src/folding_ranges.rs</a></p>



<a name="176109093"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176109093" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176109093">(Sep 19 2019 at 15:11)</a>:</h4>
<p>this definitelly should contain a MATCH_ARM_LIST: <a href="https://github.com/rust-analyzer/rust-analyzer/blob/eeac224c3543ce4c869877fe46ea8815286f97d2/crates/ra_ide_api/src/folding_ranges.rs#L84" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/blob/eeac224c3543ce4c869877fe46ea8815286f97d2/crates/ra_ide_api/src/folding_ranges.rs#L84">https://github.com/rust-analyzer/rust-analyzer/blob/eeac224c3543ce4c869877fe46ea8815286f97d2/crates/ra_ide_api/src/folding_ranges.rs#L84</a></p>



<a name="176109101"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176109101" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176109101">(Sep 19 2019 at 15:11)</a>:</h4>
<p>Do you want to open a PR ^^</p>



<a name="176109103"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176109103" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176109103">(Sep 19 2019 at 15:11)</a>:</h4>
<p>?</p>



<a name="176109204"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176109204" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176109204">(Sep 19 2019 at 15:12)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> heh, I'm not familiar with the RA infra; would take some time to learn ^^</p>



<a name="176109281"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176109281" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176109281">(Sep 19 2019 at 15:13)</a>:</h4>
<p>it's just adding that constant to "the list"?</p>



<a name="176109399"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176109399" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176109399">(Sep 19 2019 at 15:14)</a>:</h4>
<p>for folding match arms -- yeah (well, and updating the test below). For tweaking folding of <code>if</code>, I think there might be something else to do</p>



<a name="176109493"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176109493" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176109493">(Sep 19 2019 at 15:15)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span>  what FoldKind do I need to use in the tests?</p>



<a name="176109505"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176109505" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176109505">(Sep 19 2019 at 15:15)</a>:</h4>
<p>(for match)</p>



<a name="176109568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176109568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176109568">(Sep 19 2019 at 15:16)</a>:</h4>
<p>I think it should be Block as well</p>



<a name="176109623"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176109623" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176109623">(Sep 19 2019 at 15:17)</a>:</h4>
<p>Alright, I'll give it a go by just editing the file on github :P</p>



<a name="176109642"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176109642" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176109642">(Sep 19 2019 at 15:17)</a>:</h4>
<p>Let's hope it compiles :D</p>



<a name="176110349"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176110349" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176110349">(Sep 19 2019 at 15:23)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> <a href="https://github.com/rust-analyzer/rust-analyzer/pull/1873" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/pull/1873">https://github.com/rust-analyzer/rust-analyzer/pull/1873</a></p>



<a name="176110665"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176110665" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176110665">(Sep 19 2019 at 15:26)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span>  in the case of <code>if ... { ... } else { ... }</code> it seems to me (from a naive POV) that the problem is that it includes <code>else</code>in the folding</p>



<a name="176110705"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176110705" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176110705">(Sep 19 2019 at 15:27)</a>:</h4>
<p>should I file an issue?</p>



<a name="176110882"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176110882" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176110882">(Sep 19 2019 at 15:28)</a>:</h4>
<p>I am not sure, but I think it might be fixed by <a href="https://github.com/rust-analyzer/rust-analyzer/pull/1874/commits/184e80007b1d549ebabb6c7a86103648470a8c9f" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/pull/1874/commits/184e80007b1d549ebabb6c7a86103648470a8c9f">https://github.com/rust-analyzer/rust-analyzer/pull/1874/commits/184e80007b1d549ebabb6c7a86103648470a8c9f</a></p>



<a name="176110958"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176110958" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176110958">(Sep 19 2019 at 15:29)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> cool; I guess just a test is left to be added?</p>



<a name="176111049"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176111049" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176111049">(Sep 19 2019 at 15:30)</a>:</h4>
<p>That's a bug in the rust-analyzer &lt;-&gt; lsp conversion layer, and we don't add tests there</p>



<a name="176111068"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176111068" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176111068">(Sep 19 2019 at 15:30)</a>:</h4>
<p>ah</p>



<a name="176111079"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176111079" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176111079">(Sep 19 2019 at 15:30)</a>:</h4>
<p>the reason is that, to actually properly test this, you need to test against a specific client, and that's pretty brittle to setup</p>



<a name="176111156"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176111156" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176111156">(Sep 19 2019 at 15:31)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> yea, guess the testing is just opening VSCode then</p>



<a name="176111254"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176111254" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176111254">(Sep 19 2019 at 15:32)</a>:</h4>
<p>Yeah, I find that the best testing stragy for such "integration" tests is to do early releases and just let the users find the bugs</p>



<a name="176111297"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176111297" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremy Kolb <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176111297">(Sep 19 2019 at 15:33)</a>:</h4>
<p>I love little refactors like that</p>



<a name="176111470"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176111470" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176111470">(Sep 19 2019 at 15:35)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span>  aw; seems my PR failed <span aria-label="frown" class="emoji emoji-1f641" role="img" title="frown">:frown:</span> -- <a href="https://travis-ci.org/rust-analyzer/rust-analyzer/jobs/587070667" target="_blank" title="https://travis-ci.org/rust-analyzer/rust-analyzer/jobs/587070667">https://travis-ci.org/rust-analyzer/rust-analyzer/jobs/587070667</a></p>



<a name="176111483"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176111483" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176111483">(Sep 19 2019 at 15:35)</a>:</h4>
<p>looks like <code>rustfmt</code> failure</p>



<a name="176111629"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176111629" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176111629">(Sep 19 2019 at 15:36)</a>:</h4>
<p>ah, yes, will fix</p>



<a name="176111698"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176111698" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176111698">(Sep 19 2019 at 15:37)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> done</p>



<a name="176333928"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176333928" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176333928">(Sep 23 2019 at 01:32)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> updated RA to master now and the <code>else</code> issue persists</p>



<a name="176346408"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176346408" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176346408">(Sep 23 2019 at 07:38)</a>:</h4>
<p>Interesting! So it looks like Vs Code client doesn't actually take start character/end character into account?</p>
<p>I bet this is because the VS Code UI for folds is petty restricted :(</p>



<a name="176346421"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176346421" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176346421">(Sep 23 2019 at 07:38)</a>:</h4>
<p>VS Code folds like this:</p>
<p><a href="/user_uploads/4715/mU_Mhg2Bhe1zmKcMMtWMOn7M/pasted_image.png" target="_blank" title="pasted_image.png">pasted image</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/mU_Mhg2Bhe1zmKcMMtWMOn7M/pasted_image.png" target="_blank" title="pasted image"><img src="/user_uploads/4715/mU_Mhg2Bhe1zmKcMMtWMOn7M/pasted_image.png"></a></div>



<a name="176346438"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176346438" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176346438">(Sep 23 2019 at 07:39)</a>:</h4>
<p>IntelliJ folds like this:</p>
<p><a href="/user_uploads/4715/B7E3XDzf5hao1Syn9YcU8mEv/pasted_image.png" target="_blank" title="pasted_image.png">pasted image</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/B7E3XDzf5hao1Syn9YcU8mEv/pasted_image.png" target="_blank" title="pasted image"><img src="/user_uploads/4715/B7E3XDzf5hao1Syn9YcU8mEv/pasted_image.png"></a></div>



<a name="176346551"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176346551" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176346551">(Sep 23 2019 at 07:40)</a>:</h4>
<p>Apparently, VS Code simply can't fold the range in the middle.  So, to work like vs code, we should supply an "interior" of a block as a folding range, while, for intellij-like behavior, we should specify the exteriour plus a replacement string</p>



<a name="176347916"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176347916" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176347916">(Sep 23 2019 at 08:07)</a>:</h4>
<p><span class="user-mention" data-user-id="126931">@centril</span> filed <a href="https://github.com/microsoft/language-server-protocol/issues/827" target="_blank" title="https://github.com/microsoft/language-server-protocol/issues/827">https://github.com/microsoft/language-server-protocol/issues/827</a>.</p>



<a name="176347994"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176347994" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176347994">(Sep 23 2019 at 08:08)</a>:</h4>
<p>I think I wouldn't, in principle, be against the fix that makes rust behave like typescript, on the LSP layer, though I suspect it might be more involved than just "add/subtract one to the folding range boundary"</p>



<a name="176365525"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176365525" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176365525">(Sep 23 2019 at 12:58)</a>:</h4>
<p>thanks for investigating!</p>



<a name="176369387"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176369387" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176369387">(Sep 23 2019 at 13:44)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> are you sure about your screenshot ? here's how VS Code looks on my machine, notice the "..." ellipse in the folded loop <a href="/user_uploads/4715/s8oGX0aeLFAMRTPQuARltn9x/pasted_image.png" target="_blank" title="pasted_image.png">here</a>. It looks the same for other blocks like your <code>if</code> example, or in javacript for example</p>
<div class="message_inline_image"><a href="/user_uploads/4715/s8oGX0aeLFAMRTPQuARltn9x/pasted_image.png" target="_blank" title="here"><img src="/user_uploads/4715/s8oGX0aeLFAMRTPQuARltn9x/pasted_image.png"></a></div>



<a name="176369598"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176369598" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176369598">(Sep 23 2019 at 13:46)</a>:</h4>
<p><span class="user-mention" data-user-id="116113">@lqd</span> this is exactly what I am talking about: the <code>}</code> is on the new line</p>



<a name="176369617"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176369617" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176369617">(Sep 23 2019 at 13:46)</a>:</h4>
<p>the elipsis is not shown in my screenshot because the current line is highlighted</p>



<a name="176369642"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/folding%20of%20%60match%60%20and%20%60if%60/near/176369642" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/folding.20of.20.60match.60.20and.20.60if.60.html#176369642">(Sep 23 2019 at 13:46)</a>:</h4>
<p>haha ok</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>